package model

import (
	"newRetailByGolang/variable"
	"time"
)

type Agent struct {
	Id int64
	Name string
	UserId int64
	UserName string ;
	SuperiorAgencyId int64 ;
	CreatedAt time.Time
	UpdatedAt time.Time
}

func (agent *Agent) FindSubordinateAgentByUserId(id int64) []*Agent{
	var agentList []*Agent
	variable.Db.Table("agents").Joins("inner join users on agents.user_id = users.id").Where("users.id = ?", id).Find(&agentList)
	return agentList
}

func (agent *Agent) FindSubordinateAgentBySupId(id int64) []*Agent{
	var agentList []*Agent
	variable.Db.Raw("select * from agents where id in (select superior_agency_id from agents where user_id = ?)", id).Find(&agentList)
	return agentList
}

func (agent *Agent) FindSubordinateAgent(id int64) []*Agent{
	var agentList []*Agent
	variable.Db.Where("superior_agency_id = ?", id).Find(&agentList)
	return agentList
}